package demo;

public class Test1 {

    public static void main(String[] args) {

        System.out.println("这是一个test类");


        //数组
        String[] arrStr = {"aaa", "bbbbb"};

//        arrStr[2] = "cccc";  //错误

        System.out.println(arrStr);


        int[] arrInt = new int[10];

        arrInt[0] = 6;
        arrInt[1] = 6;
        arrInt[2] = 6;
        arrInt[6] = 6;

        int count = 0;
        for (int i = 0; i <arrInt.length ; i++) {
            count += arrInt[i];
        }
//        System.out.println("总和为："+count);


        //foreach
        double[] myList = {1,4, 5, 5.7,9.3 ,39.2};

        /*for (double element: myList) {
            System.out.println(element);
        }*/

//        int[] a = new int[]{1,3,5,6};
//        printArr(new int[]{1,3,5,6});

        //数组作为函数的返回值
//        reverse(new int[]{1,2,3,4,5,6,7,8});



        //二维数组
        int a[][] = new int[2][3];
        a[0][0] = 1;
        a[0][1] = 2;
        a[1][0] = 3;
        a[1][1] = 4;

        a[0][2] = 5;
//        a[0][3] = 6;

        System.out.println("二维数组"+a[0][1]);

        String s[][] = new String[2][];

        s[0]  =  new String[2];
        s[1]  =  new String[3];
        s[0][0] = "wbz";
        s[0][1] = new String("wbz1");

        s[1][0] = "wbz2";
        s[1][1] = "wbz3";
        s[1][2] = "wbz4";




    }


    public static void printArr(int[] arr) {
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
    }


    public static int[] reverse(int[] arr) {
        int[] res = new int[arr.length];

        for (int i = 0, j=res.length-1; i < arr.length; i++, j--) {
            res[j] = arr[i];
        }
        return  res;
    }




}
